#include "SpotlightElement.hpp"

SpotlightElement::SpotlightElement(float x, float y, float angle, float arc, float length, LightElement::Type lightType, b2World* world) : ActionableElement(false) {
    this->light = new LightElement(x, y, angle, arc, length, lightType, world);
    this->supportBarDirection = new b2Vec2(0.0f, 1.0f);

    b2BodyDef bodyDefinition;
    bodyDefinition.userData = this;
    bodyDefinition.position.Set(x, y);
    bodyDefinition.angle = angle;

    b2PolygonShape shape;
    shape.SetAsBox(0.35f, 0.25f);

    this->body = world->CreateBody(&bodyDefinition);
    this->body->CreateFixture(&shape, 0.0f);
}

SpotlightElement::~SpotlightElement() {
    delete this->light;
    delete this->supportBarDirection;
}

bool SpotlightElement::isSpotlight() {
    return true;
}

void SpotlightElement::setAngle(float angle) {
    this->body->SetTransform(this->body->GetPosition(), angle);
    this->light->body->SetTransform(this->light->body->GetPosition(), angle);
}

void SpotlightElement::turnOff() {
    this->light->body->SetActive(false);
}

void SpotlightElement::turnOn() {
    this->light->body->SetActive(true);
}
